package com.yic.module.device.service.inspectionPlanMessage;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.yic.module.device.controller.admin.inspectionPlanMessage.vo.*;
import com.yic.module.device.dal.dataobject.inspectionPlanMessage.InspectionPlanMessageDO;
import com.yic.framework.common.pojo.PageResult;

import com.yic.module.device.convert.inspectionPlanMessage.InspectionPlanMessageConvert;
import com.yic.module.device.dal.mysql.inspectionPlanMessage.InspectionPlanMessageMapper;

import static com.yic.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yic.module.device.enums.ErrorCodeConstants.*;

/**
 * 设备计划消息管理 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class InspectionPlanMessageServiceImpl implements InspectionPlanMessageService {

    @Resource
    private InspectionPlanMessageMapper inspectionPlanMessageMapper;

    @Override
    public Long createInspectionPlanMessage(InspectionPlanMessageCreateReqVO createReqVO) {
        // 插入
        InspectionPlanMessageDO inspectionPlanMessage = InspectionPlanMessageConvert.INSTANCE.convert(createReqVO);
        inspectionPlanMessageMapper.insert(inspectionPlanMessage);
        // 返回
        return inspectionPlanMessage.getId();
    }

    @Override
    public void updateInspectionPlanMessage(InspectionPlanMessageUpdateReqVO updateReqVO) {
        // 校验存在
        validateInspectionPlanMessageExists(updateReqVO.getId());
        // 更新
        InspectionPlanMessageDO updateObj = InspectionPlanMessageConvert.INSTANCE.convert(updateReqVO);
        inspectionPlanMessageMapper.updateById(updateObj);
    }

    @Override
    public void deleteInspectionPlanMessage(Long id) {
        // 校验存在
        validateInspectionPlanMessageExists(id);
        // 删除
        inspectionPlanMessageMapper.deleteById(id);
    }

    private void validateInspectionPlanMessageExists(Long id) {
        if (inspectionPlanMessageMapper.selectById(id) == null) {
            throw exception(INSPECTION_PLAN_MESSAGE_NOT_EXISTS);
        }
    }

    @Override
    public InspectionPlanMessageDO getInspectionPlanMessage(Long id) {
        return inspectionPlanMessageMapper.selectById(id);
    }

    @Override
    public List<InspectionPlanMessageDO> getInspectionPlanMessageList(Collection<Long> ids) {
        return inspectionPlanMessageMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InspectionPlanMessageDO> getInspectionPlanMessagePage(InspectionPlanMessagePageReqVO pageReqVO) {
        return inspectionPlanMessageMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InspectionPlanMessageDO> getInspectionPlanMessageList(InspectionPlanMessageExportReqVO exportReqVO) {
        return inspectionPlanMessageMapper.selectList(exportReqVO);
    }

}
